class Customer < ActiveRecord::Base
  belongs_to :company
  belongs_to :adder, :class_name => 'Employee', :foreign_key => 'adder_id'
  belongs_to :editor, :class_name => 'Employee', :foreign_key => 'editor_id'
  belongs_to :customer_type

  #scope :name_like, lambda { |name| { :conditions => ['name like ?', '%'+name+'%'],:include=>[:adder,:editor,:customer_type] }}

  scope :name_like, lambda {  |name,for_cbb|
    if for_cbb == 'false'
      where('name like ?', '%'+name+'%').includes([:adder,:editor,:customer_type])
    else
      where('name like ? AND is_locked = 0', '%'+name+'%').select([:id,:name,:number,:linkman,:phone,:address])
    end
  }

  scope :paginate, ->(start,limit) { offset(start.to_i).limit(limit.to_i).order("id DESC")}
end
